function loadWxScript() {
    var script = document.createElement("script");
    script.type = "text/javascript";
    script.src = 'https://res.wx.qq.com/open/js/jweixin-1.3.2.js'
    document.getElementsByTagName('head')[0].appendChild(script);
}

function ready() {
    localStorage.setItem('isWxEnv', '1')
    var links = [].slice.call(document.querySelectorAll('link'))
    var hasLink = links.some(i => i.getAttribute('href').indexOf('miniprogram.css') > -1)
    var headHTML = document.head.innerHTML
    if (!hasLink) {
        loadWxScript()
        headHTML += '<link type="text/css" rel="stylesheet" href="/css/miniprogram.css">'
        document.head.innerHTML = headHTML
        setTimeout(() => {
            wx.miniProgram.postMessage({ data: {title: document.title}})
        },500)
    }
}
var isWxEnv = localStorage.getItem('isWxEnv')
if (isWxEnv == '1') {
    ready()
} else {
    if ((!window.WeixinJSBridge || !WeixinJSBridge.invoke) ) {
        document.addEventListener('WeixinJSBridgeReady', ready, false)
    } else {
        ready()
    }
}